﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.Domain.ElevatorManage
{
    public class ElevatorJudgeInfoService : IElevatorJudgeInfoService
    {
        private readonly IElevatorJudgeInfoRepository _IElevatorJudgeInfoRepository;
        public AutoMapper.IMapper _Mapper;
        public ElevatorJudgeInfoService(IElevatorJudgeInfoRepository elevatorJudgeInfoRepository, AutoMapper.IMapper mapper)
        {
            _IElevatorJudgeInfoRepository= elevatorJudgeInfoRepository;
            _Mapper = mapper;
        }

        public async Task<ElevatorJudgeInfoDto> GetElevatorJudgeInfoByIDAsync(long id)
        {
            var elevators = await _IElevatorJudgeInfoRepository.GetByIdAsync(id);
            var elevatorDtos = _Mapper.Map<ElevatorJudgeInfo, ElevatorJudgeInfoDto>(elevators);
            return elevatorDtos;
        }

        public  async Task<PageDto<ElevatorJudgeInfoDto>> GetElevatorJudgeInfosAsync(ElevatorJudgeInfoDto elevatorJudgeInfoDto)
        {
            PageModel page = new PageModel { PageIndex = elevatorJudgeInfoDto.PageIndex, PageSize = elevatorJudgeInfoDto.PageSize, };
            var exp = Expressionable.Create<ElevatorJudgeInfo>();
            exp.AndIF(!string.IsNullOrEmpty(elevatorJudgeInfoDto.JudgeEquipmentCode), l=>l.JudgeEquipmentCode==elevatorJudgeInfoDto.JudgeEquipmentCode);

            return await _IElevatorJudgeInfoRepository.GetElevatorJudgeInfosAsync(exp.ToExpression(), page);
        }

        public async Task<bool> UpdateElevatorJudgeAsync(ElevatorJudgeInfoDto elevatorJudgeInfoDto)
        {
            var elevatorDtos = _Mapper.Map<ElevatorJudgeInfoDto, ElevatorJudgeInfo>(elevatorJudgeInfoDto);
            var res = await _IElevatorJudgeInfoRepository.UpdateAsync(elevatorDtos);
            return res;
        }
    }
}
